<?php
error_reporting( E_ALL&~E_NOTICE );
ini_set( 'display_errors', 'off' );//屏蔽错误和警告提示
include("mysql.php");
if(isset($_GET['name']) and isset($_GET['ka']))
{
$name=$_GET['name'];
$ka=htmlentities($_GET['ka']);
$check="SELECT * FROM  `ka` WHERE  `kacode` =  '$ka'";
$ret=mysql_query($check);
$row=mysql_fetch_array($ret);
if(!$row['kacode']){
    echo "此卡不存在";
    exit;
    
}
if($row['stat']=="1"){
    echo "此卡已被使用";
    exit;
}
$ka_time=$row['ka_time']; //加卡秒长
$ka_id=$row['id']; //卡的id

$mysql="SELECT * FROM  `user` WHERE  `name` =  '$name'";
$ret=mysql_query($mysql);
$row=mysql_fetch_array($ret);
if(!$row['id']){
    echo "用户不存在，若需充值此用户，请先注册";
    exit;
}
$id=$row['id'];

//$enable_time=strtotime($row['time'])-28800; //用户到期时间戳
$enable_time=strtotime($row['time']); //用户到期时间戳
if($enable_time-28800<time()){
    $enable_time=time()+28800;
}
$added_time=$enable_time+$ka_time; //加卡后的时间戳
$user_time=date("Y-m-d H:i:s",$added_time);

$mysql="UPDATE  `user` SET  `time` =  '$user_time' WHERE  `id` =$id";
mysql_query($mysql);
$mysql="UPDATE  `ka` SET  `stat` =  1 WHERE  `id` =$ka_id";
mysql_query($mysql);
echo "加卡成功！用户到期时间为".$user_time;

}
else{
    echo '无权访问该文件！';
}
?>